from django.http import JsonResponse
# Create your views here.
from django.db import connection, transaction
#from utils.sqldictfetchall import sqldictfetchall

from polls.models import TTest
#from rest_framework.views import APIView

def test1(request):
    
    return JsonResponse({"ret": '成功！'})


def test2(request):
    name=1
    with connection.cursor() as cursor:
        #事务保存点
        save_id = transaction.savepoint()
        #原生语句无法使用到model的相关设置，不会自动填充时间字段,插入只返回影响行数

        cursor.execute("SELECT * FROM t_test")
        #row = sqldictfetchall(cursor)
        row = cursor.fetchall()
        #提交事务
        transaction.savepoint_commit(save_id)
    print(row)
    return JsonResponse({"ret": '1'})
